package com.chinalwb.are.demo.slice;

import com.chinalwb.are.demo.DemoUtil;
import com.chinalwb.are.demo.ResourceTable;
import com.chinalwb.are.utils.FindUtils;
import com.chinalwb.are.utils.NoFieldTextDecorator;
import com.chinalwb.are.utils.TextDecorator;
import com.chinalwb.are.view.RichTextView;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Component;
import ohos.agp.utils.TextTool;
import ohos.agp.utils.Color;

import static com.chinalwb.are.utils.NoFieldTextDecorator.TYPE_ITALIC;


/**
 * ARE_ShowTextSlice
 *
 * @since 2021/06/22
 */
public class ARE_ShowTextSlice extends AbilitySlice {
    /**
     * DEFAULT
     */
    public static final String DEFAULT = "default";
    private static final String WARP = "\n";

    private final String html = " " + WARP + "In this release, you have a new usage with ARE" + WARP +
            " " + WARP +
            "AREditText + ARE_Toolbar, you are now able to control the position of " +
            "the input area and where to put the toolbar at and,what ToolItems you'd " +
            "like to have in the toolbar." + WARP +
            " " + WARP +
            "You can not only define the Toolbar (and it's style), " +
            "you can also add your own ARE_ToolItem with your style into ARE." + WARP +
            " " + WARP +
            "Fixed app color override bug;edit mode click picture won't open keyboard" + WARP +
            " " + WARP +
            "Why not give it a try now?";

    @Override
    protected void onStart(Intent intent) {
        DemoUtil.initStatus(getAbility());
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_show_text);
        RichTextView tvContent = FindUtils.findRichTextById(getAbility(), ResourceTable.Id_content);
        String param = getAbility().getIntent().getStringParam(DEFAULT);
        if (TextTool.isNullOrEmpty(param)) {
            TextDecorator.getInstance().setNoFieldStyle(tvContent);
        } else {
            if (param.equals(DEFAULT)) {
                findComponentById(ResourceTable.Id_text_title).setVisibility(Component.VISIBLE);
                NoFieldTextDecorator
                        .decorate(tvContent, html, false)
                        .setTextColor(Color.BLUE.getValue(),
                                "In this release, you have a new usage with ARE",
                                "AREditText + ARE_Toolbar, you are now able to control the position of " +
                                        "the input area and where to put the toolbar at and,what ToolItems you'd " +
                                        "like to have in the toolbar.",
                                "You can not only define the Toolbar (and it's style), " +
                                        "you can also add your own ARE_ToolItem with your style into ARE.",
                                "Fixed app color override bug;edit mode click picture won't open keyboard")
                        .setFont(TYPE_ITALIC, true, "Why not give it a try now?")
                        .setTextColor(Color.getIntColor("#F77EF2"), "Why not give it a try now?")
                        .build();
            } else {
                if (!TextTool.isNullOrEmpty(intent.getStringParam("content"))) {
                    tvContent.setText(intent.getStringParam("content"));
                }
            }
        }
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
